package appconfig

import (
	"fmt"
	"github.com/spf13/viper"
	"github.com/zeromicro/go-zero/core/logx"
)

type ViperData struct {
	Mysql struct {
		User string
		Pass string
		Host string
		Port int
		Data string
	}
	Redis struct {
		Addr string
		Pass string
		DB   int
	}
	AliYun struct {
		AccessKeyId     string
		AccessKeySecret string
	}
	Jwt struct {
		APP_KEY string
	}
	QiNiuYun struct {
		AccessKey string
		SecretKey string
	}
	Pay struct {
		AppId      string
		PrivateKey string
		NotifyURL  string
		ReturnURL  string
	}
}

var Conf ViperData

func Init() {
	viper.SetConfigFile("../api/appconfig/dev.yaml")
	err := viper.ReadInConfig()
	if err != nil {
		logx.Error("配置文件读取失败")
	} else {
		fmt.Println("配置文件读取成功")
	}

	err = viper.Unmarshal(&Conf)
	if err != nil {
		logx.Error("配置文件解析失败")
	} else {
		fmt.Println("配置文件解析成功")
	}
}
